  Ext.BLANK_IMAGE_URL = 'ext/images/default/s.gif';
        Ext.QuickTips.init();
        
        function progressConsole() {
		    Ext.MessageBox.show({
			   title: '请稍等',
			   msg: '正在处理...',
			   progressText: '',
			   width:300,
			   progress:true,
			   closable:false
			});
			var progressConsole = function(v){
				 return function(){
						var i = v/10;
						Ext.MessageBox.updateProgress(i, i*100+'%');
			     };
			};
			for(var i = 1; i <= 10; i++){
				setTimeout(progressConsole(i), i*150);
			}
		};
        var dstore = new Ext.data.JsonStore({
			url: '/weihe/getDTCargo_depotList',
			root: 'datas',
			fields : ['id','amount','remark','sum','supplier'
			          ,{
			        	   name:'it',mapping:'invoiceType'
			          },{
			        	   name:'iu',mapping:'invoiceUnit'
			          },{
						name:'cargoId',mapping:'cargo', convert:function(v){ 
														return v ? v.id : undefined;}
			          },{
						name:'code',mapping:'cargo', convert:function(v){ 
														return v ? v.code : undefined;}
			          },{
			        	 name:'cname',mapping:'cargo', convert:function(v){ 
														return v ? v.name : undefined;}
			          },{
			        	  name:'specs',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.specs : undefined;}
			          },{
			        	  name:'price',mapping:'cargo', convert:function(v){ 
							return v ? v.price : undefined;}
			          },{
			        	  name:'location',mapping:'cargo', convert:function(v){ 
							return v ? v.location : undefined;}
			          },{
			        	  name:'place',mapping:'cargo', convert:function(v){ 
							return v ? v.place : undefined;}
			          },{
			        	  name:'unit',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.unit : undefined;}
			          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        var depotStore = new Ext.data.JsonStore({
			url: '/weihe/getList_depotList',
			root: 'datas',
			fields : [{
			        	   name:'depotId',mapping:'id'
			          },{
			        	   name:'depotOrderNum',mapping:'orderNum' 
			          },{
        				   name:'depotListNum',mapping:'listNum'
        			  },{
        				   name:'depotDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
        				   name:'depotDepartment',mapping:'department'
        			  },{
        				   name:'depotType',mapping:'type'
        			  },{
        				   name:'depotRemark',mapping:'remark'
        			  },{
        				   name:'depotWarehouse',mapping:'warehouse'
        			  },{
        				   name:'depotMaker',mapping:'maker'
        			  },{
        				   name:'depotAuditor',mapping:'auditor'
        			  },{
        				   name:'depotFlag',mapping:'flag'
        			  }],
        		baseParams : {'tab': '入库'},
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        var depotSLStore = new Ext.data.JsonStore({
			url: '/weihe/getSLCargo_shoppingList',
			root: 'datas',
			fields : [{
			        	   name:'shopId',mapping:'id'
			          },{
			        	   name:'shopAmount',mapping:'amount' 
			          },{
        				   name:'shopPrice',mapping:'price'
        			  },{
        				   name:'shopRemark',mapping:'remark'
        			  },{
        				   name:'shopState',mapping:'state'
        			  },{
        				   name:'shopCount',mapping:'count'
        			  },{
        				   name:'shopSum',mapping:'sum'
        			  },{
			        	   name:'cargoId',mapping:'cargo', convert:function(v){ 
														return v ? v.id : undefined;}
			          },{
			        	   name:'shopName',mapping:'cargo', convert:function(v){ 
														return v ? v.name : undefined;}
			          },{
        				   name:'shopOrigin',mapping:'cargo', convert:function(v){ 
														return v ? v.origin : undefined;}
        			  },{
						   name:'shopCode',mapping:'cargo', convert:function(v){ 
														return v ? v.code : undefined;}
			          },{
			        	   name:'shopSpecs',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.specs : undefined;}
			          },{
			        	   name:'shopUnit',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.unit : undefined;}
			          },{
			        	   name:'shopPlace',mapping:'cargo', convert:function(v){ 
			        	  								return v ? v.place : undefined;}
			          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}

		});
        
        
        

        
    
    	
    
    	

depots = function(){
	
	var tmp;
	var slCode;
	
  return{
	  
	  
		listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height : 230,
			                    items  : [depots.listGrid(),depots.listForm()] 
		                      });
	  
	  return listPanel;
},

listForm : function(){
	  
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					Ext.getCmp("goodsForm").buttons[0].enable();
					Ext.getCmp("goodsForm").buttons[1].enable();
					Ext.getCmp("goodsForm").buttons[2].enable();
					if (listForm.form.findField("depotId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_depotList',
						     success : function(form, action) {
							      if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								       depotSLStore.baseParams = {'query' : listForm.form.findField('depotList.orderNum').getValue()};
									   depotSLStore.load({params : {start : 0, limit : 6}});
									    Ext.getCmp("goodsForm").form.findField('depotList.id').setValue(action.result.depotList_id);
									    Ext.getCmp("depotListGrid").getStore().load({params : {start : action.result.total-1, limit : 6}});
									    listForm.form.reset();
									    Ext.getCmp("dgrid").getStore().removeAll();
								        });
							       }
						     }
					      });
					}else {
							listForm.form.submit({
								url : '/weihe/update_depotList',
								success : function(form, action) {
								  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("depotListGrid").getStore().reload();
										});
									}
							   }
							});
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
			Ext.getCmp("goodsForm").form.reset();
			Ext.getCmp("goodsForm").buttons[0].disable();
		    Ext.getCmp("goodsForm").buttons[1].disable();
		    Ext.getCmp("goodsForm").buttons[2].disable();
		    depotSLStore.removeAll();
		    Ext.getCmp("dgrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('depotId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_depotList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									listForm.form.reset();
									listForm.buttons[0].setText('添加');
							}else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("depotListGrid").getStore().load({params : {start : 0, limit : 6}});
								listForm.form.reset();
								listForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'depotList.id' : listForm.form.findField('depotId').getValue() }
				});
			}
		}
	});
	
	  
	  var whComboData = new Ext.data.SimpleStore({
			fields : ['text'],
			data : [['A'],['B'],['C']]
		});
	  
	  var typeComboData = new Ext.data.SimpleStore({
		  fields : ['text'],
		  data : [['收货'],['采购']]
	  });
			var listForm = new Ext.form.FormPanel({
			id : 'depotListForm',
			title : '产品入库信息',
			region : 'east',
			frame : true,
			width : 300,
			collapseMode :'mini',
			collapsible : true,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'depotId',
				xtype : 'hidden',
				name : 'depotList.id'
			},{
				id: 'depotListNum',
				xtype : 'hidden',
				name : 'depotList.listNum'
			},{
				id: 'depotFlag',
				xtype : 'hidden',
				name : 'depotList.flag',
				value : '入库'
			},{
				id: 'depotOrderNum',
				fieldLabel: "采购单号",
          	    name: "depotList.orderNum"
			},{
				id: 'depotDate',
                xtype: 'datefield',
                fieldLabel: "入库日期",
                format : 'Y-m-d',
    			allowBlank:false,
                name: "depotList.date"
			},{
				id:'depotType',
				fieldLabel : '入库类别',
 				name : 'depotList.type',
 				xtype : 'combo',
 				store : typeComboData,
 				emptyText : '请选择',
 				mode : 'local',
 				triggerAction : 'all',
 				allowBlank:false,
 				editable: false,
 				displayField : 'text'
			},{
				id:'depotWarehouse',
				fieldLabel : '仓库',
 				name : 'depotList.warehouse',
 				xtype : 'combo',
 				store : whComboData,
 				emptyText : '请选择',
 				mode : 'local',
 				triggerAction : 'all',
 				allowBlank:false,
 				editable: false,
 				displayField : 'text'
			},{
				id: 'depotDepartment',
				 fieldLabel: "部门",
               name: "depotList.department"
			},{
				id: 'depotRemark',
				 fieldLabel: "备注",
                name: "depotList.remark"
			},{
				id: 'depotMaker',
				 fieldLabel: "制单人",
               name: "depotList.maker"
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},

  	infoWin : function(){
  	  var infoWin = new Ext.Window({
  	  	id: 'depotInfo',
        title:'入库单查询',
        layout: 'fit',
        width:330,    
        height:250,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[depots.queryForm()] 
        
    });  
  		return infoWin;
  	},
  	
  	queryForm : function(){
  		
  		 var typeComboData = new Ext.data.SimpleStore({
												fields : ['text'],
												data : [['收货'],['采购']]
												});
  	 var queryForm = new Ext.form.FormPanel({
			baseCls:"x-plain",
			frame : true,
			autoHeight : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
					  fieldLabel: "采购单号",
      	    		  name: "depotList.orderNum"
			 	  },{
					  fieldLabel: "入库单号",
      	    		  name: "depotList.listNum"
			 	  },{
					  fieldLabel: "部门",
      	    		  name : 'depotList.department'
			 	  },{
					  fieldLabel : '入库类别',
				      name : 'depotList.type',
					  xtype : 'combo',
					  store : typeComboData,
				      emptyText : '请选择',
					  mode : 'local',
					  triggerAction : 'all',
					  editable: false,
				      displayField : 'text'
				   },{
            		  xtype: 'datefield',
                      fieldLabel: "开始日期", //第三行，出生日期 
                      format : 'Y-m-d',
            		  name: "depotList.date"
				   },{
            		  xtype: 'datefield',
                      fieldLabel: "结束日期", //第三行，出生日期 
                      format : 'Y-m-d',
            		  name: "depotList.endDate"
				   }],
			buttons:[{
        		 text:'确认',
             	 handler:function(){
             	 	var orderNum = queryForm.form.findField('depotList.orderNum').getValue();
             	 	var listNum = queryForm.form.findField('depotList.listNum').getValue();
             	 	var department = queryForm.form.findField('depotList.department').getValue();
             	 	var type = queryForm.form.findField('depotList.type').getValue();
             	 	var date = queryForm.form.findField('depotList.date').getValue();
             	 	var endDate = queryForm.form.findField('depotList.endDate').getValue();
				 Ext.getCmp("depotListGrid").getStore().baseParams = {'flag': true,'tab':'入库','depotList.orderNum':orderNum,
					 													  'depotList.listNum':listNum,
					 													  'depotList.type':type,
					 													  'depotList.department':department,
					 													  'depotList.date':date,
					 													  'depotList.endDate':endDate};
				 Ext.getCmp("depotListGrid").getStore().load({params : {start : 0, limit : 6}});
				 queryForm.form.reset();
                  Ext.getCmp("depotInfo").close();
              	
              	}
              },{
                 text:'取消',
                 handler:function(){
                 	queryForm.form.reset();
                 	Ext.getCmp("depotInfo").close();
                 }
              }]   
        });
        return queryForm;
  	
  	},
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : depotStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'depotListGrid',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : depotStore,
		   columns: [
		             {header : '采购单号', dataIndex : 'depotOrderNum'},
		             {header : '入库单号', dataIndex : 'depotListNum'},
		             {header : '入库日期', dataIndex : 'depotDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '入库类别', dataIndex : 'depotType', menuDisabled : true},
		             {header : '部门', dataIndex : 'depotDepartment', menuDisabled : true},
		             {header : '仓库', dataIndex : 'depotWarehouse', menuDisabled : true},
		             {header : '备注', dataIndex : 'depotRemark', menuDisabled : true},
		             {header : '制单人', dataIndex : 'depotMaker', menuDisabled : true},
		             {header : '审核人', dataIndex : 'depotAuditor', menuDisabled : true}
		             ],
         sm : rowSelectionModel,
         tbar:[{
	   						text:"输入查询条件",
								handler:function(){
										depots.infoWin().show();
								}
	   					},"-",{
	   						text:"查看全部",
								handler:function(){
									Ext.getCmp("depotListGrid").getStore().baseParams = {'flag': false,'tab':'入库'};
									Ext.getCmp("depotListGrid").getStore().load({params : {start : 0, limit : 6}});
								}
	   			},"-"],
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		Ext.getCmp("depotListForm").form.loadRecord(record);
			   		tmp = record.get('depotWarehouse');
			   		depotSLStore.removeAll();
			   		depotSLStore.baseParams = {'query' : record.get('depotOrderNum')};
					depotSLStore.load({params : {start : 0, limit : 6}});
			   		Ext.getCmp("goodsForm").form.findField('depotList.id').setValue(record.id);
			   		Ext.getCmp("goodsForm").buttons[0].enable();
					Ext.getCmp("goodsForm").buttons[1].enable();
					Ext.getCmp("goodsForm").buttons[2].enable();
					Ext.getCmp("depotListForm").buttons[0].setText('修改');
					Ext.getCmp("dgrid").getStore().baseParams = {'depotList.id': record.id};
					Ext.getCmp("dgrid").getStore().load({params : {start : 0, limit : 6}});
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
	
	gridPanel : function(){
		  
		var gridPanel = new Ext.Panel( {
			                    region : 'center',
			                    layout : 'border',
			                    frame  : true,
			                    items  : [depots.grid(),depots.slGrid()] 
		                      });
	  
			return gridPanel;
		},
	
	
	slGrid : function(){
		 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : depotSLStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var slGrid = new Ext.grid.GridPanel({
		   title : '采购单货物表',
		   border:'true',
		   region : 'west',
		   width : 380,
		   collapseMode :'mini',
		   collapsible : true,
		   split : true,
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : depotSLStore,
		   columns: [
		             {header : '产品名称', dataIndex : 'shopName'},
		             {header : '数量', dataIndex : 'shopAmount', menuDisabled : true},
		             {header : '已采购量', dataIndex : 'shopCount', menuDisabled : true},
		             {header : '状态', dataIndex : 'shopState', menuDisabled : true,renderer:function(value){
		           																						if(value == '未完成'){
		           																							return "<span style='color:red;font-weight:bold;'>未完成</span>";
		           																						}else{
		           																							return "<span style='color:green;font-weight:bold;'>已完成</span>";
		           																						}
		             }},
		             {header : '单价', dataIndex : 'shopPrice',sortable : true},
		             {header : '金额', dataIndex : 'shopSum', menuDisabled : true},
		             {header : '备注', dataIndex : 'shopRemark', menuDisabled : true}
	    ],
	       sm : rowSelectionModel,
	       listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			     Ext.getCmp("goodsForm").form.findField('cname').setValue(record.get('shopName'));
			     Ext.getCmp("goodsForm").form.findField('code').setValue(record.get('shopCode'));
			     Ext.getCmp("goodsForm").form.findField('specs').setValue(record.get('shopSpecs'));
			     Ext.getCmp("goodsForm").form.findField('unit').setValue(record.get('shopUnit'));
			     Ext.getCmp("goodsForm").form.findField('price').setValue(record.get('shopPrice'));
			     Ext.getCmp("goodsForm").form.findField('place').setValue(record.get('shopPlace'));
			     Ext.getCmp("goodsForm").form.findField('cargo.id').setValue(record.get('cargoId'));
			     Ext.getCmp("goodsForm").form.findField('slId').setValue(record.id);
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
	});
		return slGrid;
		},
  
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 6,
			store : dstore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'dgrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : dstore,
		   columns: [
		             {header : '产品编号', dataIndex : 'code', menuDisabled : true},
		             {header : '产品名称', dataIndex : 'cname'},
		             {header : '规格型号', dataIndex : 'specs', menuDisabled : true},
		             {header : '单位', dataIndex : 'unit', menuDisabled : true},
		             {header : '所在仓库', dataIndex : 'location', menuDisabled : true},
		             {header : '存放位置', dataIndex : 'place', menuDisabled : true},
		             {header : '数量', dataIndex : 'amount', menuDisabled : true},
		             {header : '单价', dataIndex : 'price',sortable : true},
		             {header : '金额', dataIndex : 'sum', menuDisabled : true},
		             {header : '供应商', dataIndex : 'supplier', menuDisabled : true},
		             {header : '发票类型', dataIndex : 'it', menuDisabled : true},
		             {header : '开票单位', dataIndex : 'iu', menuDisabled : true},
		             {header : '备注', dataIndex : 'remark', menuDisabled : true}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   Ext.getCmp("goodsForm").form.loadRecord(record);
			   Ext.getCmp("goodsForm").buttons[0].setText('修改');
			   if(record.get('it') != '无票'){
			    	Ext.getCmp("goodsForm").form.findField('iu').enable();
			   }
			  
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	},
	goodsForm : function(){
		
		
		var codestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByCode_shoppingList',
			root: 'codes',
			fields: ['code']
		
		});
		
		var namestore = new Ext.data.JsonStore({
			url: '/weihe/getCargosByname_shoppingList',
			root: 'names',
			fields: ['name']

		});
		
		var codeCombo = {
				id : 'code',
				xtype: 'combo',
				fieldLabel: '产品编号',
				store: codestore,
				typeAhead: false,
				name: 'cargo.code',
				loadingText: '查找中...',
				emptyText: '请输入3位以上编号', 
				minChars: 3,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'code',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getCode_depotList',
								success : function(response) {
									  var json = Ext.decode(response.responseText);
									  goodsForm.form.findField('cname').setValue(json.name);
									  goodsForm.form.findField('specs').setValue(json.specs);
									  goodsForm.form.findField('unit').setValue(json.unit);
									  goodsForm.form.findField('price').setValue(json.price);
									  goodsForm.form.findField('place').setValue(json.place);
									  goodsForm.form.findField('cargoId').setValue(json.id);
									},
								params : {'query' : record.get('code')}
							});
				    }
				}
		}
		var nameCombo = {
				id : 'cname',
				xtype: 'combo',
				fieldLabel: '产品名称',
				store: namestore,
				typeAhead: false,
				name: 'cargo.name',
				loadingText: '查找中...',
				emptyText: '请输入产品名称', 
				minChars: 2,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'name',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getName_depotList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									  goodsForm.form.findField('code').setValue(json.code);
									  goodsForm.form.findField('specs').setValue(json.specs);
									  goodsForm.form.findField('unit').setValue(json.unit);
									  goodsForm.form.findField('price').setValue(json.price);
									  goodsForm.form.findField('place').setValue(json.place);
									  goodsForm.form.findField('cargoId').setValue(json.id);
									},
									params : {'query' : record.get('name')}
							});
				    }
				}
		}
		


		var button_add = new Ext.Button({
			text : '添加',
			disabled : true,
			handler : function() {

					progressConsole();
				if(goodsForm.form.isValid()){ 	
					if (goodsForm.form.findField("dt_Cargo.id").getValue() == "") {
						goodsForm.form.submit({
						  url : '/weihe/addDTCargo_depotList',
						   success : function(form, action) {
							  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									 depotSLStore.reload();
									 var i = goodsForm.form.findField('depotList.id').getValue();
									   goodsForm.form.reset();
									   goodsForm.form.findField('depotList.id').setValue(i);
									   Ext.getCmp("dgrid").getStore().baseParams = {'depotList.id': i};
									   Ext.getCmp("dgrid").getStore().load({params : {start : 0, limit : 6}});
									    goodsForm.form.findField('iu').disable();
								})
							  }
						    },
						    failure : function(form, action) {
      							Ext.Msg.alert('错误', action.result.msg);
      						}
					    })
					}else {
						goodsForm.form.submit({
							  url : '/weihe/updateDTCargo_depotList',
							   success : function(form, action) {
								  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								 	depotSLStore.reload();
									Ext.Msg.alert('消息', action.result.msg, function() {
										var i = goodsForm.form.findField('depotList.id').getValue();
										goodsForm.form.reset();
										goodsForm.form.findField('iu').disable();
										 goodsForm.form.findField('depotList.id').setValue(i);
										Ext.getCmp("dgrid").getStore().reload();
										 goodsForm.form.findField('iu').disable();
										    goodsForm.buttons[0].setText('添加');
										
									})
								  }
							    },
							    failure : function(form, action) {
	      							Ext.Msg.alert('错误', action.result.msg);
	      						}
						    })

				
						
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		text : '清空',
		disabled : true,
		handler : function() {
		var i = goodsForm.form.findField('depotList.id').getValue();
			goodsForm.form.reset();
			goodsForm.form.findField('iu').disable();
			goodsForm.form.findField('depotList.id').setValue(i);
		    goodsForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		disabled : true,
		handler : function() {
			var id = goodsForm.form.findField('dt_Cargo.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteDTCargo_depotList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
						   if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									goodsForm.form.reset();
									goodsForm.buttons[0].setText('添加');
						   }else{
							depotSLStore.reload();
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("dgrid").getStore().load({params : {start : 0, limit : 6}});
								var i = goodsForm.form.findField('depotList.id').getValue();
								goodsForm.form.reset();
								goodsForm.form.findField('iu').disable();
								goodsForm.form.findField('depotList.id').setValue(i);
								goodsForm.buttons[0].setText('添加');
								 goodsForm.form.findField('iu').disable();
							});
						   }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'dt_Cargo.id': id , 'depotList.id' : goodsForm.form.findField('depotList.id').getValue() }

				});
			}
		}
	});
	
	  var itComboData = new Ext.data.SimpleStore({
			fields : ['text'],
			data : [['增税'],['普票'],['无票']]
		});
	  


		var goodsForm = new Ext.form.FormPanel({
			id : 'goodsForm',
			title : '货物信息',
			frame : true,
			width : 300,
			region : 'east',
			autoScroll : true,
			collapseMode :'mini',
			collapsible : true,
			labelAlign : 'right',
			labelWidth : 60,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
				id: 'id',
				xtype : 'hidden',
				name : 'dt_Cargo.id'
			},{
				xtype : 'hidden',
				name : 'depotList.id'
			},{ 
				id: 'cargoId',
				xtype : 'hidden', 
				name : 'cargo.id'
			},{  // SL_CARGO 的id
				xtype : 'hidden',
				name : 'slId'
			},codeCombo ,nameCombo
			 ,{
				id:'specs',
				fieldLabel : '规格型号',
				name : 'cargo.specs',
				allowBlank:false,
				blankText:'请输入规格型号'
			},{
				id:'unit',
				fieldLabel : '单位',
				allowBlank:false,
				name : 'cargo.unit',
				blankText:'请输入单位'
			},{
				id:'place',
				fieldLabel : '存放位置',
 				name : 'cargo.place',
 				allowBlank:false,
 				blankText:'请输入存放位置'
			},{
				id:'price',
				fieldLabel : '单价',
				name : 'dt_Cargo.price',
				allowBlank:false,
				blankText:'请输入单价',
				regex : /^\d+(\.\d+)?$/,
			    regexText:'请输入有效的价格'         
			
			},{
				id:'amount',
				fieldLabel : '数量',
				allowBlank:false,
				name : 'dt_Cargo.amount',
				blankText:'请输入数量',
				regex : /^[1-9]\d*$/,
			    regexText:'请输入有效的数量'  
			},{
				id:'supplier',
				fieldLabel : '供应商',
 				name : 'dt_Cargo.supplier',
 				allowBlank:false,
 				blankText:'请输入供应商'
			},{
				id:'it',
				fieldLabel : '发票类型',
 				name : 'dt_Cargo.invoiceType',
 				xtype : 'combo',
 				store : itComboData,
 				emptyText : '请选择',
 				mode : 'local',
 				value : '无票',
 				triggerAction : 'all',
 				allowBlank:false,
 				editable: false,
 				displayField : 'text',
 				listeners :{ 'select':function(combo, record,index){
 										if(record.get('text') != "无票"){
 										    goodsForm.form.findField('iu').enable();
 										}else{
 											goodsForm.form.findField('iu').setValue("");
 											goodsForm.form.findField('iu').disable();
 										}
				    				}
 							}
				    
			},{
				id:'iu',
				fieldLabel : '开票单位',
 				name : 'dt_Cargo.invoiceUnit',
 				disabled : true
			},{	id:'remark',
				fieldLabel : '备注',
				name : 'dt_Cargo.remark'
			}],
			buttons : [button_add,button_clear,button_del]
		
	});
		return goodsForm;
	}
  }
}();








